(function(){"use strict";BX.namespace("BX.Landing");BX.Landing.EditDomainForm=function(t,i){this.domain=t.querySelector(".ui-domain-input-btn-js");this.postfix=t.querySelectorAll(".ui-postfix");this.domains=t.querySelectorAll(".ui-domainname");this.content=i.content||"";this.messages=i.messages||{};this.fieldId=i.fieldId||"domain_id";this.popup=new BX.PopupWindow("landing-domain-popup",null,{titleBar:this.messages.title,content:this.content,contentBackground:"#eef2f4",overlay:true,buttons:[new BX.PopupWindowButton({id:"landing-popup-window-button-accept",text:BX.message("BLOCK_CONTINUE"),className:"popup-window-button-accept"}),new BX.PopupWindowButton({text:BX.message("BLOCK_CANCEL"),className:"popup-window-button-link",events:{click:function(){this.popupWindow.close()}}})]});BX.bind(this.domain,"click",BX.delegate(this.showPopup,this))};BX.Landing.EditDomainForm.prototype={showPopup:function(){for(var t=0,i=this.postfix.length;t<i;t++){if(BX(BX.data(this.postfix[t],"input-id")).value){this.postfix[t].checked=true}}this.popup.show()},editDomain:function(){var t="";for(var i=0,e=this.postfix.length;i<e;i++){if(this.postfix[i].checked&&typeof this.domains[i]!=="undefined"){this.domains[i].value=BX.util.trim(this.domains[i].value);if(this.domains[i].value!==""){t=this.domains[i].value+this.postfix[i].value}}}BX(this.fieldId+"_title").textContent=t;BX(this.fieldId).value=t}};BX.Landing.DomainNamePopup=function(t){this.params=t;this.messages=t.messages||{};this.dialog=new BX.Landing.EditDomainForm(BX("ui-editable-domain"),{fieldId:t.fieldId,messages:{title:this.messages.title||"",errorEmpty:this.messages.errorEmpty||""},content:BX("ui-editable-domain-content")});this.domainRadioBtn=this.dialog.popup.contentContainer.querySelectorAll(".ui-radio");this.domainInput=this.dialog.popup.contentContainer.querySelectorAll(".ui-domainname");this.inpList=this.dialog.popup.contentContainer.querySelectorAll("input.ui-domainname");this.textNode1=this.dialog.popup.contentContainer.querySelector("#landing-form-domain-name-text");this.textNode2=this.dialog.popup.contentContainer.querySelector("#landing-form-domain-any-name-text");this.saveBtn=BX("landing-popup-window-button-accept");this.clickBySavebtn=false;for(var i=0,e=this.domainRadioBtn.length;i<e;i++){BX.bind(this.domainRadioBtn[i],"click",BX.delegate(function(t){var i=t.target.nextElementSibling.querySelector(".ui-domainname");var e=t.target.nextElementSibling.querySelector(".landing-site-name-status");this.runDomainCheck(i,e)},this))}for(var n=0,a=this.domainInput.length;n<a;n++){var s=this.domainInput[n];s.addEventListener("keyup",BX.debounce(function(t){var i=new Date-this.time;if(i<1e3){return}this.onKeyUp(t)},1e3,this))}for(var n=0;n<this.inpList.length;n++){BX.bind(this.inpList[n],"focus",BX.delegate(function(t){t.target.parentNode.previousElementSibling.checked=true;var i=t.target.parentNode.querySelector(".landing-site-name-status");this.runDomainCheck(t.target,i)},this))}BX.bind(this.saveBtn,"click",BX.delegate(function(){this.findSelectedItem();this.clickBySavebtn=true},this));BX.addCustomEvent(this.dialog.popup,"onPopupShow",BX.delegate(function(){this.findSelectedItem()},this))};BX.Landing.DomainNamePopup.prototype={runDomainCheck:function(t,i){this.findUnselectedItem();this.isAvailableDomain=null;this.isDeletedDomain=null;this.handlerDomainName(t.value,t);if(this.isAvailableDomain!==null&&this.isDeletedDomain!==null){this.highlight(this.isAvailableDomain,this.isDeletedDomain,t,i)}},fillInstruction:function(t){var i=t.split(".");var e=/^(com|net|org)\.[a-z]{2}$/;this.textNode2.parentNode.style.display="none";this.textNode1.textContent=t?t:"landing.mydomain";if(i.length===2||i.length===3&&i[0]==="www"||i.length===3&&(i[1]+"."+i[2]).match(e)){this.textNode2.parentNode.style.display="table-row";if(i.length===3&&i[0]==="www"){this.textNode2.textContent=i[1]+"."+i[2]}else{this.textNode1.textContent="www."+t;this.textNode2.textContent=t}}this.textNode1.textContent=BX.util.trim(this.textNode1.textContent)+".";this.textNode2.textContent=BX.util.trim(this.textNode2.textContent)+"."},onKeyUp:function(t){this.time=new Date;this.handlerDomainName(t.target.value,t.target)},closePopup:function(){if(this.isAvailableDomain){this.dialog.editDomain();this.dialog.popup.close()}},ajax:function(t,i){BX.ajax({url:"/bitrix/tools/landing/ajax.php?action=Domain::check",method:"POST",data:{data:{domain:t+i,filter:{"!ID":BX(this.params.fieldId+"_id").value}},sessid:BX.message("bitrix_sessid")},dataType:"json",onsuccess:function(t){if(t.result){this.isAvailableDomain=t.result.available;this.isDeletedDomain=t.result.deleted;if((i===".bitrix24.site"||i===".bitrix24.shop"||i===".bitrix24site.by"||i===".bitrix24shop.by")&&this.domainRadioBtn[0].checked){this.checkSubdomain()}else{this.fillInstruction(t.result.domain);if(this.domainRadioBtn[1].checked){var e=t.result.domain.length;this.checkDomain(e)}}if(this.clickBySavebtn){this.closePopup()}this.clickBySavebtn=false}}.bind(this)})},checkSubdomain:function(){var t=this.domainRadioBtn[0].nextElementSibling.querySelector(".ui-domainname");var i=this.domainRadioBtn[0].nextElementSibling.querySelector(".landing-site-name-status");var e=t.value;if(this.domainRadioBtn[0].checked){if(!(e==="")&&!/^[\w_\-]+$/.test(e)){this.addDisableClass(t);i.textContent=BX.message("LANDING_DOMAIN_INCORRECT");return}else{this.removeDisableClass(t);i.textContent=""}this.saveBtn.classList.remove("btn-disabled");if(t.classList.contains("ui-domainname-unavailable")){t.classList.remove("ui-domainname-unavailable");i.textContent=""}this.highlight(this.isAvailableDomain,this.isDeletedDomain,t,i)}},checkDomain:function(t){var i=this.domainRadioBtn[1].nextElementSibling.querySelector(".ui-domainname");var e=this.domainRadioBtn[1].nextElementSibling.querySelector(".landing-site-name-status");var n=i.getAttribute("maxlength");if(t>=n&&n!==null){this.addDisableClass(i);e.textContent=BX.message("LANDING_DOMAIN_LIMIT_LENGTH")}else{this.saveBtn.classList.remove("btn-disabled");if(i.classList.contains("ui-domainname-unavailable")){i.classList.remove("ui-domainname-unavailable");e.textContent=""}this.highlight(this.isAvailableDomain,this.isDeletedDomain,i,e)}},handlerDomainName:function(t,i){var e=t;var n=BX.data(i,"postfix");this.ajax(e,n)},removeDisableClass:function(t){t.classList.remove("ui-domainname-unavailable");this.saveBtn.classList.remove("btn-disabled")},addDisableClass:function(t){t.classList.add("ui-domainname-unavailable");this.saveBtn.classList.add("btn-disabled")},resetHighlight:function(t,i){t.classList.remove("ui-domainname-available");t.classList.remove("ui-domainname-unavailable");i.textContent=""},findUnselectedItem:function(){for(var t=0,i=this.domainRadioBtn.length;t<i;t++){if(!this.domainRadioBtn[t].checked){var e=this.domainRadioBtn[t].nextElementSibling.querySelector(".ui-domainname");var n=this.domainRadioBtn[t].nextElementSibling.querySelector(".landing-site-name-status");this.resetHighlight(e,n)}}},findSelectedItem:function(){for(var t=0,i=this.domainRadioBtn.length;t<i;t++){var e=this.domainRadioBtn[t].nextElementSibling.querySelector(".ui-domainname");var n=this.domainRadioBtn[t].nextElementSibling.querySelector(".landing-site-name-status");if(this.domainRadioBtn[t].checked){this.runDomainCheck(e,n)}}},highlight:function(t,i,e,n){if(t){if(e.value===""){this.saveBtn.classList.add("btn-disabled")}else{this.removeDisableClass(e)}n.textContent="";e.classList.add("ui-domainname-available")}else{if(i){n.textContent=BX.message("LANDING_DOMAIN_EXIST2")}else{n.textContent=BX.message("LANDING_DOMAIN_EXIST")}this.addDisableClass(e);e.classList.remove("ui-domainname-available")}}}})();
//# sourceMappingURL=script.map.js